<template>
  <div class="photoInfo-container">
    <h3>{{photoInfo.title}}</h3>

    <p class="subtitle">
      <span>发表时间：{{photoInfo.add_time | dateFormat}}</span>
      <span>点击：{{photoInfo.click}}次</span>
    </p>
    <hr />

    <!-- 缩略图区域 -->
    <!-- <img v-for="(item,index) in list" 
            :key="item.src" 
            :src="item.src" 
            class="preview-img" 
            height="100" 
    @click="$preview.open(index,list)">-->
    <div class="thumbs">
      <vue-preview class="imgPrev" :slides="list"></vue-preview>
    </div>
    <!-- 图片内容区域 -->
    <div class="content">
      <span v-html="photoInfo.content"></span>
    </div>

    <!-- 评论区域 子组件 -->
    <cmt-box :id="id"></cmt-box>
  </div>
</template>

<script>
//1、导入评论子组件
import content from "../subcomponents/Common.vue";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      id: this.$route.params.id, //从路由中获取到的id
      photoInfo: {}, //图片详情
      list: [] //缩略图的数组
    };
  },
  created() {
    this.getPhotoInfo();
    this.getThumbs();
  },
  methods: {
    getPhotoInfo() {
      //获取图片详情
      this.$http.get("getimageInfo/" + this.id).then(res => {
        if (res.body.status === 0) {
          this.photoInfo = res.body.message[0];
        } else {
          Toast("获取图片详情失败！");
        }
      });
    },
    //获取缩略图
    getThumbs() {
      this.$http.get("getthumimages/" + this.id).then(res => {
        if (res.body.status === 0) {
          //循环每张图片，不全图片的宽和高
          res.body.message.forEach(item => {
            item.w = 600;
            item.h = 400;
            item.src = item.src;
            item.msrc = item.src;
          });
          this.list = res.body.message;
        } else {
          Toast("获取图片缩略图失败！");
        }
      });
    }
  },
  components: {
    "cmt-box": content //2、注册评论子组件
  }
};
</script>

<style lang="scss" scoped>
.photoInfo-container {
  padding: 3px;

  h3 {
    color: #26a2ff;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }
  .content {
    font-size: 13px;
    line-height: 30px;
  }
}
</style>